package com.pks.autoInsurance.dao;

import java.sql.Connection;
import java.sql.SQLException;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

/**
 * Contains JDBC Connection information. Should be inherited by all the DAO
 * implementation classes
 * 
 * @author Pankaj Soni
 */
public abstract class AutoInsuranceDAO {
	/**
	 * @return Connection to the database
	 */
	public final Connection getConnection() {
		// System.out.println(getClass() + "::::getConnection::::begin");
		try {
			final DataSource ds = (DataSource) new InitialContext()
					.lookup("java:/comp/env/jdbc/oracledb");
			Connection connection = ds.getConnection();
			return connection;
		} catch (NamingException e) {
			System.err.println(getClass() + "::::" + e.getMessage());
		} catch (SQLException e) {
			System.err.println(getClass() + "::::" + e.getMessage());
		}
		return null;
	}
}
